import 'package:enterprise_v6_app/app/core/http/http.dart';
import 'package:enterprise_v6_app/app/core/utils/interface.dart';
import 'package:enterprise_v6_app/app/data/entities/application/basic_information/certificate_file_entity.dart';
import 'package:get/get.dart';

class CertificateFileDetailsController extends GetxController {
  /// 文件id
  final String id = Get.arguments as String;

  /// 详情实体
  CertificateFileEntity fileEntity = CertificateFileEntity();

  /// 证照照片
  List<String> picList = [];

  @override
  void onInit() {
    super.onInit();
    getDetailsData();
  }

  /// 获取详情数据
  void getDetailsData() async {
    // 获取详情接口
    final res = await HttpUtil().generateGetRequest<CertificateFileEntity>(
      Interface.getCertificateFile,
      queryParameters: {'id': id},
    ).execute();
    res.onSuccess((result) {
      if (result.data != null) {
        fileEntity = result.data!;
        // 添加证照图片
        if (fileEntity.certificateBackUrl!.isNotEmpty) {
          picList.add(fileEntity.certificateBackUrl!);
        }
        if (fileEntity.certificateFrontUrl!.isNotEmpty) {
          picList.add(fileEntity.certificateFrontUrl!);
        }
      }
      update();
    });
  }
}
